package com.tjetc.view.manage;

import com.tjetc.domain.*;
import com.tjetc.proxy.ClientProxy;
import com.tjetc.service.DoctorMessageService;
import com.tjetc.service.DoctorService;
import com.tjetc.service.ParentService;
import com.tjetc.vo.AppDate;
import com.tjetc.vo.Result;

import java.util.List;
import java.util.Scanner;

public class ParentMainView {
    private Scanner scanner=new Scanner(System.in);
    private ParentService parentService= ClientProxy.getProxyInstance(ParentService.class);
    private DoctorMessageService doctorMessageService=ClientProxy.getProxyInstance(DoctorMessageService.class);
    public void start() {
        while (true){
            try {
                System.out.println("1.查询孩子的基础信息");
                System.out.println("2.查询孩子的疾病表");
                System.out.println("3.查询孩子的疫苗接种表");
                System.out.println("4.修改密码");
                System.out.println("5.查看所有医生信息");
                System.out.println("0.返回上一级");
                int i = scanner.nextInt();
                switch (i){
                    case 1:
                        sel();
                        break;
                    case 2:
                        selD();
                        break;
                    case 3:
                        selY();
                        break;
                    case 4:
                        upd();
                        break;
                    case 5:
                        list();
                        break;
                    case 0:
                        return;
                }
            } catch (Exception e) {
                System.out.println("输入错误,请重新输入");
                scanner.nextLine();
            }
        }
    }

    private void list() {
        List<Doctormessge> list=doctorMessageService.list();
        for (Doctormessge doctormessge : list) {
            System.out.println(doctormessge);
        }
    }

    private void upd() {
        int parentId = AppDate.loginParent.getId();
        System.out.println("请输入原密码");
        String password=scanner.next();
        String password1=AppDate.loginParent.getPassword();
        if (!(password.equals(password1))){
            System.out.println("密码输入错误");
        }else {
            System.out.println("请输入修改后的密码");
            String password2= scanner.next();
            Result result=parentService.upd(password2,parentId);
            System.out.println(result.getMsg());
        }
    }
    private void selY() {
        int parentId = AppDate.loginParent.getId();
        List<Vaccination> list=parentService.selY(parentId);
        for (Vaccination vaccination : list) {
            System.out.println(vaccination);
        }
    }
    private void selD() {
        int parentId = AppDate.loginParent.getId();
        List<Health> list1=parentService.serch1(parentId);
        for (Health health : list1) {
            System.out.println(health);
        }
    }
    private void sel() {
        int parentId = AppDate.loginParent.getId();
        List<Newborn> list=parentService.sel2(parentId);
        for (Newborn newborn : list) {
            System.out.println(newborn);
        }
    }
}
